<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  
  <head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" th:href="@{/pages/favicon.ico}" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{/pages/css/font.css}" href="./css/font.css">
    <link rel="stylesheet" th:href="@{/pages/css/xadmin.css}" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="./lib/layui/layui.js" th:src="@{/pages/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/pages/js/xadmin.js}" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a><cite>banner列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>

    <div class="x-body">
      <div class="layui-row">

          <!--<input class="layui-input" placeholder="开始日" name="start" id="start">
          <input class="layui-input" placeholder="截止日" name="end" id="end">-->


      </div>
      <xblock>
        <button class="layui-btn" type="button" lay-filter="add" onclick="openAdd('添加banner','/manage/banner/toAdd')"><i class="layui-icon"></i>添加</button>
        <span class="x-right" style="line-height:40px">共有数据：<span th:text="${bannerPageInfo.total}"></span> 条</span>
      </xblock>
      <form class="layui-form layui-col-md12 x-so" th:action="@{/manage/banner/toList}" method="post">
        <input type="hidden" name="pageNum" value="0"/>
      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>图片</th>
            <th>链接地址</th>
            <th>位置</th>
            <th>是否启用</th>
            <th>创建时间</th>
            </tr>
        </thead>
        <tbody>
          <tr th:each="banner:${bannerPageInfo.list}">
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td><img th:src="${banner?.imgPath}"/></td>
            <td th:text="${banner?.directUrl}"></td>
            <td th:if="${#strings.equals(banner?.type,'1')}">中间轮播</td>
            <td th:if="${#strings.equals(banner?.type,'2')}">banner右侧</td>
            <td th:if="${#strings.equals(banner?.type,'3')}">banner背景</td>
            <td><input type="checkbox" lay-filter="isUsed" th:attr="fid=${banner.id}" lay-skin="switch" lay-text="启用|禁用" th:checked="${banner?.isUsed=='0'}"></td>
            <td th:text="${#dates.format(banner?.gmtCreate,'yyyy-MM-dd HH:mm:ss')}"></td>
          </tr>
        </tbody>
      </table>
      <div class="page" id="page">

      </div>
    </div>
    </form>
    <script th:inline="javascript">
      var pageNum = [[${bannerPageInfo.pageNum}]];
      var totalNum = [[${bannerPageInfo.total}]];

      layui.use(['laydate','form','layer'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
          layer = parent.layer === undefined ? layui.layer : parent.layer,
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });

          form.on('switch(isUsed)', function(data){
              var index = layer.msg('修改中，请稍候',{icon: 16,time:false,shade:0.8});
              setTimeout(function(){
                  layer.close(index);
                  var fid = $(data.elem).attr("fid");
                  $.post("/manage/banner/update",{"id":fid},function (data) {
                      layer.msg(data);
                  });
              },500);
          })

      });

      function openAdd(title,url) {
          var w=($(window).width()*0.9);
          var h=($(window).height() - 50);
          layer.open({
              type: 2,
              area: [w+'px', h +'px'],
              fix: false, //不固定
              maxmin: true,
              shadeClose: true,
              shade:0.4,
              title: title,
              content: url
          });
      }


      layui.use('laypage', function(){
          var laypage = layui.laypage;

          //执行一个laypage实例
          laypage.render({
              elem: 'page',
              curr:pageNum,
              count:totalNum,
              limit:10,
              jump:function (obj,first) {
                  console.log(obj.curr);
                  $("input[name='pageNum']").val(obj.curr);
                  if(!first) {
                      $("form").submit();
                  }
              }
          });
      });

      function formSubmit() {
          $("input[name='pageNum']").val(0);
      }
    </script>
  </body>

</html>